from rest_framework.mixins import ListModelMixin,CreateModelMixin,RetrieveModelMixin,DestroyModelMixin,UpdateModelMixin
from utils.common_response import APIResponse



class CommonListModelMixin(ListModelMixin):
    def list(self,request,*args,**kwargs):
        res = super().list(request, *args, **kwargs)
        return APIResponse(data=res.data)

class CommonCreateModelMixin(CreateModelMixin):
    def create(self, request, *args, **kwargs):
        res = super().create(request, *args, **kwargs)
        return APIResponse(data=res.data)  # {code:100,msg:成功，data:{}}


class CommonUpdateModelMixin(UpdateModelMixin):
    def update(self, request, *args, **kwargs):
        res = super(CommonUpdateModelMixin, self).update(request, *args, **kwargs)
        return APIResponse(data=res.data)


class CommonRetrieveModelMixin(RetrieveModelMixin):
    def retrieve(self, request, *args, **kwargs):
        res = super(CommonRetrieveModelMixin, self).retrieve(request, *args, **kwargs)
        return APIResponse(data=res.data)


class CommonDestroyModelMixin(DestroyModelMixin):
    def destroy(self, request, *args, **kwargs):
        res = super().destroy(request, *args, **kwargs)
        return APIResponse(msg='删除成功')